// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Table/TABLED1Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Table/TABLED1Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Table/ITABLED1Service.h"

#include "Import/BDFImport/BDFParserBase.h"

using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
using namespace SG::DBManager;
using namespace SG::Import;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class TABLED1ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (TABLED1ParserTest, ParseEntry1)
{
    // 1 假设BDF文件文本内容，通过解析函数加入到数据库中（需要更改）

    std::vector<std::string> Entry = { "TABLED1  2",
                                       "*        -.004           0.              0.              0.",
                                       "*        4.2105265-4     .6142127        8.4210531-4     .9694003",
                                       "*        .0012632        .9157733        .0016842        .4759474",
                                       "*        .0021053        -.1645948       .0025263        -.7357239",
                                       "*        .0029474        -.9965845       .0033684        -.8371664",
                                       "*        .0037895        -.3246998       .0042105        .3246993",
                                       "        .0046316.8371664.0050526.9965845.0054737.7357237.0058947.1645937",
                                       "*        .0063158        -.4759478       .0067368        -.9157738",
                                       "*        .0071579        -.9693998       .0075789        -.6142116",
                                       "*        .008            2.1305289-6     .04             0.",
                                       "*        .044            0.              ENDT" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);

    SG::Import::BDF::BULKDATA::ParseTABLED1 (DB_SERVICEFACTORY, dividedEntryInfo);

    // // 2 使用DBM接口获取对应的结构体数据（需要更改）
    SG::DataStructure::FEM::TABLED1Data data;

    DB_SERVICEFACTORY->get<ITABLED1Service> ()->FindById (2, data);
    // // 3 检查解析后的数据（需要更改）
    ASSERT_TRUE (data.m_id == 2);
    ASSERT_TRUE (data.m_CODEX == 0);
    ASSERT_TRUE (data.m_CODEY == 0);
    ASSERT_TRUE (data.m_XYList.size () == 23);
}
